package com.example.consult.controller;

import com.example.consult.mapper.QuestionMapper;
import com.example.consult.model.QuestionTable;
import com.example.consult.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//自助服务
@RequestMapping("/SelfService")
@Controller
public class QuestionController {
    @Autowired
    QuestionService questionService;

    @Autowired
    QuestionMapper questionMapper;

    /**
     *
     * @param classifyTitle 根据指定分类找标题
     * @return
     */
    @RequestMapping(value = "searchTitle",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getTitle(@RequestParam String classifyTitle){
        return questionMapper.getQuestionByClassifyTitle(classifyTitle);
    }

    /**
     * 获取所有分类
     * @return
     */
    @RequestMapping(value = "searchClassify",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getClassify(){
        return questionMapper.getQuestionFirst();
    }

    /**
     * 获取指定答案
     * @return
     */
    @RequestMapping(value = "searchAnswer",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getAnswer(@RequestParam String title){
        return questionService.getQuestionByTitle(title);
    }

    /**
     * 获取点击率最高的
     * @return
     */
    @RequestMapping(value = "searchMost",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getMost(){
        return questionMapper.getQuestionClickMost();
    }

    @RequestMapping(value = "searchByNameAndClassify",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getAnswersByClassify(@RequestParam String classify,String title){
        return questionService.getQuestionByClassify(classify,title);
    }

    @RequestMapping(value = "searchByKey",method = RequestMethod.POST)
    @ResponseBody
    public List<QuestionTable> getAnswers(@RequestParam String key){
        return questionMapper.getQuestionByKeyword(key);
    }

}
